<!--
/**************************************************
* @ balancemanage.jsp
*
* Copyright   2006 Hitrust Technology Inc.
* Developed by SDC, Hitrust.
* All Rights Reserved.
*
* Modify History:
*  v1.00, 2006/04/17, Jenny Li
*  1) first release
/**************************************************
-->
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ include file="../../common.jsp" %>
<%@ taglib uri="/page.util.gs.hitrust.com/taglibs/page" prefix="page"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	<title>对帐调整</title>
	<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<LINK href="<%=root%>/css/caigouxitong.css"" type=text/css rel=stylesheet>		
	<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
	<SCRIPT language="JavaScript" src="<%=root%>/js/calendar.js"></SCRIPT>
	<%
		ArrayList tOrderDeptList = (ArrayList)request.getAttribute("shiporg");
		ResultProcess tBalanceMsg = (ResultProcess)request.getAttribute("balancemsg");
		String tRequery = (String)request.getAttribute("requery");
	    ArrayList tList = new ArrayList();
	%>	
	<script>

	var counter;
	function process(val){
		if(val == 'Q'){
			balancemanage.action = "<%=response.encodeURL(root + "/A180202.do")%>";
    		balancemanage.submit();			
		}else if(val == 'C'){
			balancemanage.orderDeptId.value="0000";
			balancemanage.provider.value="";
            balancemanage.provider.value="";
			balancemanage.status.value="00";
			var t = new Date();
			var year = t.getYear();
			var mm = t.getMonth();

			var listbox = document.getElementById("Select2");
			for(i=0; i<listbox.length; i++){
				if(listbox[i].value == year){
					listbox[i].selected = true;
				}
			}
			listbox = document.getElementById("Select3");
			for(i=0; i<listbox.length; i++){
				if(listbox[i].value == mm + 1){
					listbox[i].selected = true;
				}
			}
            			
		}else if(val == 'PC'){
			if(!confirm("是否确定生成本月应付款?")){
				return false;
			}
			balancemanage.action = "<%=response.encodeURL(root + "/A180221.do")%>";
			balancemanage.submit();
		}
	}
	function control(val,id,year,month,sum){
		if(val == 'F'){
			if(!confirm("是否确定作废删除?")){
				return false;
			}
			pager.deptId.value=id;
			if(month.length == 1){
				month = "0" + month;
			}
			pager.balanceYM.value=year + month;
			//保存查询参数
			pager.orderDeptId.value = balancemanage.orderDeptId.value;
			pager.provider.value = balancemanage.provider.value;
			pager.payType.value = balancemanage.payType.value;
			pager.balanceType.value = balancemanage.balanceType.value;
			pager.status.value = balancemanage.status.value;
			pager.balanceYear.value = balancemanage.balanceYear.value;
			pager.balanceMonth.value = balancemanage.balanceMonth.value;
			pager.action="<%=response.encodeURL(root + "/A180203.do")%>";
			pager.submit();
		}else if(val == 'P'){
			pager.deptId.value=id;
			if(month.length == 1){
				month = "0" + month;
			}
			pager.balanceYM.value=year + month;
			pager.deptCategory.value="2";

			var url = "<%=response.encodeURL(root + "/A180205.do")%>?deptId="+id+"&balanceYM="+(year+month)+"&balanceSum="+sum+"&deptCategory=2";
			result = showModalDialog(url, window,"status:yes;unadorned:no;dialogWidth:650px;dialogHeight:650px;help:yes;resizable:yes;scroll:yes;");
			if(result != null ){
				receivesubmitform.orgId.value = result[0];
				receivesubmitform.orgCategory.value = "2";				
				receivesubmitform.balancYM.value = result[1];		
				//receivesubmitform.subOrgId.value = result[8];		
				receivesubmitform.notes.value = result[7];
				for(i=0; i<result[2].length;i++){
					receivesubmitform.costType[i].value = result[2][i];
					receivesubmitform.payTypes[i].value = result[3][i];				
					receivesubmitform.balSum[i].value = result[4][i];
					receivesubmitform.recvDate[i].value = result[5][i];				
					receivesubmitform.principal[i].value = result[6][i];
					
				}
				//保存查询参数
				receivesubmitform.orderDeptId.value = balancemanage.orderDeptId.value;
				receivesubmitform.provider.value = balancemanage.provider.value;
				receivesubmitform.payType.value = balancemanage.payType.value;
				receivesubmitform.balanceType.value = balancemanage.balanceType.value;
				receivesubmitform.status.value = balancemanage.status.value;
				receivesubmitform.balanceYear.value = balancemanage.balanceYear.value;
				receivesubmitform.balanceMonth.value = balancemanage.balanceMonth.value;
				receivesubmitform.action = "<%=response.encodeURL(root + "/A180206.do")%>";
				receivesubmitform.submit();
			}

		}else if(val == 'R'){
			pager.deptId.value=id;
			if(month.length == 1){
				month = "0" + month;
			}
			//pager.balanceYM.value=year + month;
			//pager.deptCategory.value="1";
			//pager.balanceSum.value = sum;			
			//pager.action="<%=response.encodeURL(root + "/A180204.do")%>";
			//pager.submit();		
			var url = "<%=response.encodeURL(root + "/A180204.do")%>?deptId="+id+"&balanceYM="+(year+month)+"&balanceSum="+sum+"&deptCategory=1";
			var result = null;	
			result = showModalDialog(url, window,"status:yes;unadorned:no;dialogWidth:650px;dialogHeight:700px;help:yes;resizable:yes;scroll:yes;");
			if(result != null ){
				receivesubmitform.orgId.value = result[0];
				receivesubmitform.orgCategory.value = "1";				
				receivesubmitform.balancYM.value = result[1];		
				receivesubmitform.subOrgId.value = result[8];		
				receivesubmitform.notes.value = result[7];
				for(i=0; i<result[2].length;i++){
					receivesubmitform.costType[i].value = result[2][i];
					receivesubmitform.payTypes[i].value = result[3][i];				
					receivesubmitform.balSum[i].value = result[4][i];
					receivesubmitform.recvDate[i].value = result[5][i];				
					receivesubmitform.principal[i].value = result[6][i];
				}
								//保存查询参数
				receivesubmitform.orderDeptId.value = balancemanage.orderDeptId.value;
				receivesubmitform.provider.value = balancemanage.provider.value;
				receivesubmitform.payType.value = balancemanage.payType.value;
				receivesubmitform.balanceType.value = balancemanage.balanceType.value;
				receivesubmitform.status.value = balancemanage.status.value;
				receivesubmitform.balanceYear.value = balancemanage.balanceYear.value;
				receivesubmitform.balanceMonth.value = balancemanage.balanceMonth.value;
				
				receivesubmitform.action = "<%=response.encodeURL(root + "/A180206.do")%>";
				receivesubmitform.submit();
			}
		}
	}
	function control2(id,year,month,status,category,msg){
            if(month.length == 1){
                month = "0" + month;
            }
            var url="";
            if(category=='1'){
                if(status == '0'){//结算状态
                    url = "<%=response.encodeURL(root + "/A181205.do")%>?deptId="+id+"&balanceYM="+(year+month) + "&deptCategory="+category;
                }else if(status == '1'){
                    url = "<%=response.encodeURL(root + "/A181204.do")%>?deptId="+id+"&balanceYM="+(year+month) + "&deptCategory="+category;
                }
                window.open(url);
            }else if(category=='2'){
                if(status == '0'){//结算状态
                    url = "<%=response.encodeURL(root + "/A180208.do")%>?deptId="+id+"&balanceYM="+(year+month) + "&deptCategory="+category;
                }else if(status == '1'){
                    url = "<%=response.encodeURL(root + "/A180209.do")%>?deptId="+id+"&balanceYM="+(year+month) + "&deptCategory="+category;
                }
                window.open(url);
            }
	}
	function isRequery(){
			<%
				if(tRequery != null && tRequery.equals("true")){
			%>
			balancemanage.action = "<%=response.encodeURL(root + "/A180202.do")%>";
    		balancemanage.submit();			
			<%		
				}
			%>
	}
    function selectCompany()
    {
        var url = "/XMGS/A401103.do";
           var returnv = window.open(url,null," edge: sunken ,center: Yes, help: No, resizable: Yes, status: No,height=580px, scrollbars=yes");

    }   
    function exchangeDept(){
        var category = document.getElementById("Select6");
        if(category.selectedIndex==0){
            document.getElementById("prov").style.display = 'none';
            document.getElementById("dept").style.display = '';
        }else{
            document.getElementById("dept").style.display = 'none';
            document.getElementById("prov").style.display = '';
        }
    }
	</script>
	</head>
	<body BGCOLOR="#f2f2f2" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="isRequery()">
		<form name="balancemanage" method="get">
			<p><FONT face="宋体"></FONT><FONT face="宋体"></FONT><br>
			</p>
			<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
				<tr>
					<td height="20">
						<table width="100%" border="0" cellspacing="0" cellpadding="1">
							<tr height="20">
								<td height="30" width="758" class="mtxt_black">对帐单管理</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td class="bg_line" height="2"></td>
				</tr>
			</table>
			<br>
			<table class="bg_table" id="Table1" style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px" cellSpacing="1"
				cellPadding="0" width="98%" align="center" border="0">
				<TR height="20">
					<TD class="bg_column" align="center">收付款类型</TD>
                    <TD class="bg_row_odd">
                    <select id="Select6" name="payType" onchange="exchangeDept();">
                            <%
                                String payTp = request.getParameter("payType");
                                String[][] tRs = GSBaseManager.getAllPayType();
                                for(int i=0; i < tRs.length; i++){
                                    String[] temp = tRs[i];
                                    if(payTp != null && payTp.equals(temp[0])){
                            %>
                                    <option value="<%=temp[0]%>" selected><%=temp[1]%></option>                                     
                            <%
                                    }else{
                            %>
                                    <option value="<%=temp[0]%>"><%=temp[1]%></option>                          
                            <%      }
                                }
                            %>
                        </select>
                    </TD>
                    <TD class="bg_column" align="center" width="15%">结算单位</TD>
					<TD class="bg_row_odd" width="35%">
						<select name="orderDeptId" id="dept">					
						<option value="0000">---全部---</option>
						<%
							String tOrderDept = request.getParameter("orderDeptId");
							if(tOrderDeptList != null && tOrderDeptList.size() > 0 ){	
							    if(tOrderDept != null && tOrderDept.equals("0000")){
									for(int i=0; i<tOrderDeptList.size(); i++){
									    String[] temp = (String[])tOrderDeptList.get(i);
						%>
										<option value="<%=temp[0]%>"><%=temp[1]%></option>						
						<%			    
									}
							    }else{
									for(int i=0; i<tOrderDeptList.size(); i++){
									    String[] temp = (String[])tOrderDeptList.get(i);
										if(tOrderDept != null && tOrderDept.equals(temp[0])){
							%>
											<option value="<%=temp[0]%>" selected>
											<%=temp[1]%></option>
							<%				    
										}else{
							%>
											<option value="<%=temp[0]%>"><%=temp[1]%></option>
							<%			
										}
									}
							    }
							}

						%>
						</select>	
                        <select id="Select4" name="balanceType" style="display:none">
                            <option value="1" >--全部--</option>                          
                            <%
                                String balType = request.getParameter("balanceType");
                                tRs = GSBaseManager.getAllBalanceType();
                                for(int i=0; i < tRs.length; i++){
                                    String[] temp = tRs[i];
                                    if(balType != null && balType.equals(temp[0])){
                            %>
                            <option value="<%=temp[0]%>" selected><%=temp[1]%></option>                             
                            <%
                                    }else{
                            %>
                            <option value="<%=temp[0]%>"><%=temp[1]%></option>                          
                            <%      
                                    }
                                }
                            %>
                        </select>
                        <div id="prov" style="display:none;">                   
                        <input type="text" name="provider" id="provider_id" value="<%=request.getParameter("provider")==null?"":request.getParameter("provider") %>">   
                        </div>				
					</TD>
										
				</TR>
				<tr height="20">
					<TD class="bg_column" align="center" width="15%">状态</TD>
					<TD class="bg_row_odd" width="35%">
					<select id="Select5" name="status">
							<option value="00" selected>--全部--</option>
							<%
								String tStauts = request.getParameter("status");
								tRs = GSBaseManager.getAllBalanceFlag();
								for(int i=0; i < tRs.length; i++){
								    String[] temp = tRs[i];
								    if(tStauts != null && tStauts.equals(temp[0])){
							%>
									<option value="<%=temp[0]%>" selected><%=temp[1]%></option>	
							<%	    	
								    }else{
							%>
									<option value="<%=temp[0]%>"><%=temp[1]%></option>							
							<%	    
								    }
								}
							%>
						</select>
					</TD>
					<TD class="bg_column" align="center">月份</TD>
					<TD class="bg_row_odd">
						<SELECT ID="Select2" NAME="balanceYear">
						<%
							String tSelYear = request.getParameter("balanceYear");
							int length = 15;
							Calendar cal = Calendar.getInstance();
							int curYear = cal.get(Calendar.YEAR);
							for(int i=0; i<length; i++){
								if(tSelYear != null){
									if(tSelYear.equals(String.valueOf(2006+i))){
						%>
									<OPTION value="<%=2006+i%>" selected><%=2006+i%></OPTION>		
						<%			
									}else{
						%>
									<OPTION value="<%=2006+i%>"><%=2006+i%></OPTION>						
						<%				
									}
								}else if(curYear == (2006 + i)){
						%>
							<OPTION value="<%=2006+i%>" selected><%=2006+i%></OPTION>						
						<%	        
							    }else{
						%>
							<OPTION value="<%=2006+i%>"><%=2006+i%></OPTION>						
						<%		    
							    }
							}
						%>
						</SELECT>年
						<SELECT ID="Select3" NAME="balanceMonth" >
						<%
							String tSelMonth = request.getParameter("balanceMonth");
							int curMonth = cal.get(Calendar.MONTH);
							for(int i=1; i<=12; i++){
								if(tSelMonth != null){
									if(tSelMonth.equals(String.valueOf(i))){
						%>
						
									<OPTION value="<%=i%>" selected><%=i%></OPTION>	
						<%			
									}else{
						%>
									<OPTION value="<%=i%>"><%=i%></OPTION>												
						<%			
									}
								}else if(curMonth + 1 == i){
						%>
									<OPTION value="<%=i%>" selected><%=i%></OPTION>						
						<%
								}else{
						%>		
									<OPTION value="<%=i%>"><%=i%></OPTION>												
						<%		    
							    }
							}
						%>
						</SELECT>月
					</TD>
				</tr>
			</table>
            <%if(tBalanceMsg != null){
                    int totalRecords = 0;
                    int defaultPageSize = 10;
                    totalRecords = tBalanceMsg.getRecordsSize();
            %>          
            <page:pager total='<%=totalRecords%>' defaultPageSize='<%=defaultPageSize%>'>
            <%tList = tBalanceMsg.getDisplayRecords(index.intValue(),pageSize.intValue()); %>
            </page:pager>
            <%} %>
		</form>
		<p align="center">
			<INPUT type="button" value="查询" class="kuang" ID="Button1" NAME="Button1" onclick="process('Q')">&nbsp;&nbsp;
			<INPUT type="button" value="清空" ID="Button2" NAME="Button2" class="kuang" onClick="process('C')">
		</p>
<%
	if(tBalanceMsg != null){
	    
%>
    <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
    <td>
            <form name='pager' method="post">	
			 <input type="hidden" name="deptId">											
			 <input type="hidden" name="balanceYM">	
			 <input type="hidden" name="deptCategory">	
			 <input type="hidden" name="balanceSum">				 		
			 <input type="hidden" name="orderDeptId">
			 <input type="hidden" name="provider">
			 <input type="hidden" name="balanceType">
			 <input type="hidden" name="payType">
			 <input type="hidden" name="status">
			 <input type="hidden" name="balanceYear"> 			 
			 <input type="hidden" name="balanceMonth"> 			 			 
            	<table class=bg_table id=tableId	cellspacing=1 cellpadding=2 width=100% align=center border=0>
            	<tbody>
			<tr class="bg_column" height="20">
				<td class="top" align="center" colSpan="10"><b>对帐单信息列表</b>
				</td>
			</tr>
			
					<%
					if(tList != null && tList.size() > 0){
					%>
				<tr class="bg_column" height="20">
					<td align="right" colSpan="10">
		    		<page:navigator type='text' queryForm="balancemanage"/>					
					</td>
				</tr>		    		
					<%    
					}
					%>

			<tr class="bg_column" height="20">
				<td class="top" align="center" colSpan="2">
					<div class="txt_content" align="center"></div>
				</td>
				<td class="top" align="center">
					<div class="txt_content" align="center">结算单位</div>
				</td>
                <td class="top" align="center">
                    <div class="txt_content" align="center">公司名称</div>
                </td>
				<td class="top" align="center">
					<div class="txt_content" align="center">类型</div>
				</td>
				<td class="top" align="center">
					<div class="txt_content" align="center">结算年份</div>
				</td>
				<td class="top" align="center">
					<div class="txt_content" align="center">结算月份</div>
				</td>
				<td class="top" align="center">
					<div class="txt_content" align="center">金额（元）</div>
				</td>
				<td class="top" align="center">
					<div class="txt_content" align="center">状态</div>
				</td>
			</tr>
			<%
				if(tList != null && tList.size() > 0){
				    String temp = "";
				    for(int i=0; i<tList.size(); i++){
				        
				        String tStr[] = (String[])tList.get(i);
				        String trClass = "";
						if(i%2==0){
						    trClass="bg_row_odd";
						}else {
						    trClass="bg_row_even";
						}
			%>
							<tr class="<%=trClass%>" height=20>															 
								<!--td class=top align=middle> 	
									<div align="center" class="txt_content">
									<%
										if(tStr[2].equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE) && tStr[6].equals(GSBaseConstants.UNBALANCE_STATUS)){
									%>
									<input type="button" value="作废删除" class="kuang" onClick="control('F','<%=tStr[0]%>','<%=tStr[3]%>','<%=tStr[4]%>','')"> 
									<%	    
										}
									%>
									
									</div>								
								</td-->							
								<td class=top align=middle> 	
									<div align="center" class="txt_content">
									<input type="button" value="明细调整" class="kuang" onClick="control2('<%=tStr[0]%>','<%=tStr[3]%>','<%=tStr[4]%>','<%=tStr[6]%>','<%=tStr[2]%>','<%=tStr[11]%>')"> 
                                    </div>
								</td>
								<td class=top align=middle> 	
									<div align="center" class="txt_content">
									<%
										if(tStr[6].equals(GSBaseConstants.UNBALANCE_STATUS)){
										    if(tStr[2].equals(GSBaseConstants.BALANCE_ORDERDEPT_TYPE)){
									%>
									<input type="button" value="生成应收" class="kuang" onClick="control('R','<%=tStr[0]%>','<%=tStr[3]%>','<%=tStr[4]%>','<%=tStr[5]%>')"> 
									<%	        
										    }else if(tStr[2].equals(GSBaseConstants.BALANCE_PROVIDER_TYPE)){
									%>
									<input type="button" value="生成应付" class="kuang" onClick="control('P','<%=tStr[0]%>','<%=tStr[3]%>','<%=tStr[4]%>','<%=tStr[5]%>')"> 									
									<%	        
										    }
										}
									%>
									</div>
								</td>
								<%
								
									if(tStr[9]!=null && !tStr[9].trim().equals("")){
										//System.out.println(tStr[9]);
								%>
								<td class=top align=middle rowspan="<%=tStr[9]%>"> 	
									<div align="center" class="txt_content">
										<%=tStr[10] %>									
									</div>
								</td>		
								
								<%	    
									}
								%>	
                                <td class=top align=middle>     
                                    <div align="center" class="txt_content">
                                        <%=tStr[1] %>                                   
                                    </div>
                                </td>													
								<td class=top align=middle> 	
									<div align="center" class="txt_content">
										<%=GSBaseManager.getBalanceDeptTypeName(tStr[2])%>									
									</div>
								</td>						
								<td class=top align=middle> 	
									<div align="center" class="txt_content">
										<%=tStr[3]%>年									
									</div>
								</td>														
								<td class=top align=middle> 	
									<div align="center" class="txt_content">
										<%=tStr[4]%>月									
									</div>
								</td>				
								<td class=top align=middle> 	
									<div align="center" class="txt_content">
										<%=tStr[5]%>									
									</div>
								</td>														
								<td class=top align=middle> 	
									<div align="center" class="txt_content">
										<%=GSBaseManager.getBalanceFlagName(tStr[6])%>									
									</div>
								</td>														
																		
							</tr>
			<%				
				    }
			%>
							<tr class="bg_column" height="20">
								<td colspan="10" align="right">
						    		<page:navigator type='text' queryForm="balancemanage"/>
								</td>
							</tr>
			<%	    
				}else{
			%>
							<font color="red">没有符合条件的对帐单信息</font>
			<%				    
				}
			%>
			</tbody>
			</table>
			</form>
			</td>
			</tr>
		</table>				
<%	    
	}
	if(tBalanceMsg == null && tRequery != null && tRequery.equals("true")){
%>
	    	<font size="2">数据查询中......</font>
<%
   	}
%>		
<form name="receivesubmitform" method="post">
	<input type="hidden" name="orgId">
	<input type="hidden" name="balancYM">
	<input type="hidden" name="orgCategory">
	<input type="hidden" name="subOrgId">
	<input type="hidden" name="notes">
	<input type="hidden" name="orderDeptId">
	<input type="hidden" name="provider">
	<input type="hidden" name="balanceType">	
	<input type="hidden" name="payType">	
	<input type="hidden" name="status">	
	<input type="hidden" name="balanceYear">	
	<input type="hidden" name="balanceMonth">	
	<%
		for(int i=0; i<6; i++){
	%>
	<input type="hidden" name="costType">
	<input type="hidden" name="recvDate">					
	<input type="hidden" name="principal">					
	<input type="hidden" name="payTypes">						
	<input type="hidden" name="balSum">							
	<%
		}
	%>
</form>
<script type="text/javascript">
exchangeDept();
</script>
</body>
</html>
